package com.huawei.hwclouds.lubanops.demo.web.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.huawei.hwclouds.lubanops.demo.order.client.OrderServiceClient;
import com.huawei.hwclouds.lubanops.demo.product.client.ProductServiceClient;
import com.huawei.hwclouds.lubanops.demo.shoppingcart.client.ShoppingCartServiceClient;

@RequestMapping(value = "/apm2/demo/web/", produces = "application/json; charset=utf-8")
@RestController
public class WebController {

    @PostMapping("/product/info")
    public void productInfo(@RequestBody String param) {
        ProductServiceClient.queryProductInfo(param);
    }

    @PostMapping("/shopping/info")
    public void shoppingCartInfo(@RequestBody String param) {
        ShoppingCartServiceClient.queryShoppingCarts(param);
    }

    @GetMapping("/shopping/error/{id}")
    public String shoppingError(@PathVariable("id") int id) {
        return ShoppingCartServiceClient.error(id);
    }

    @PostMapping("/add/shopping/cart")
    public void appendShoppingCart(@RequestBody String param) {
        ShoppingCartServiceClient.addShoppingCart(param);
    }

    @PostMapping("/order/info")
    public void orderInfo(@RequestBody String param) {
        OrderServiceClient.orderInfo(param);
    }

    @PostMapping("/settle/account")
    public void reduceOrder(@RequestBody String param) {
        ShoppingCartServiceClient.settleAccounts(param);
    }

    @GetMapping("/product/{id}")
    public String product(@PathVariable("id") int id) {
        return OrderServiceClient.productInfo(id);
    }

}
